< previous page page_253 next page >

Page 253
LISTING 11.6.CONTINUED
9f8044bafea36a1f728739c0bb58ef4c.gif
21: Private theBusinessMemento As BusinessMemento
22: Private Enum eMemento
23:     bMyName = 0
24: End Enum

In the createMemento method, the array, arrMemento, is created. This array can hold as many items as there are properties in the class. Here, the Array statement is used to create the array, but you can create your array by using the regular Dim statement. The object theBusinessMemento is then instantiated, and its setState method is invoked, whereupon the array arrMemento is passed as an argument. Finally, a reference to theBusinessMemento is passed back to theFormController (or any client, for that matter, because more than one form controller can request a Memento).
When the user stimulates an undo operation, theFormController invokes the setMemento method, passing in the reference to theBusinessMemento it received from invoking the createMemento method. A local variable, PreviousState, is created to hold the reference to the state array returned when invoking the getState method of the Memento. In this simple example, there's only one property for theBusiness. The private enum eMemento, then, has only one enumerator, bMyName, which is set to zero. The property MyName is restored to the value referenced in PreviousState(eMemento.bMyName), which in your example is "John Conley".
In theForm (which represents frmTest), the call to trigger the undo operation looks like the following:
Private Sub cmdUndo_Click()
    theFormController.clickedUndoBtn
End Sub
Tip
The enumerator
bMyName is prefixed with the letter b. This is purely arbitrary in order to differentiate it from the actual property name. If you don't differentiate the enumerator from the actual property name, Visual Basic will return an error because it considers two or more declarations of the same name in the same module ambiguous.

The method clickedSaveBtn involves triggering the operation to persist information to some file or database. The general name for any form of persistence is information repository. In the FormController class, the method would be declared as
Public Sub clickedSaveBtn()

 
< previous page page_253 next page >

If you like this book, buy it!